import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state:{//设置全局访问的state
        crumbs:"首页",
        userid:null,
        type:null,
        user:null,
        permission:null,
        //设置的初始属性值
        newStorge:{},
        tzxtsz:null,
        token:null,
        // userid:null,
        headImg:null,
		
        //图片地址
		// pathimg:'http://192.168.0.100:8884/file/show/',
        pathimg:'http://39.96.59.234:8884/file/show/',
        uploadImgurl:'',
        imageUrls:'http://39.96.59.234:8884/file/show/',
        num:0,
        storName: '',
		system:null,
		TabStatus:null
    },
    getters:{//实时监听state值得变化
        user(state){
            if(!state.user){
                state.user = JSON.parse(sessionStorage.getItem("key"))
            }
            return state.user
        },
        headImg(state){
            if(!state.headImg){
                state.headImg = JSON.parse(sessionStorage.getItem("headImg"))
            }
            return state.headImg
        },
        // permission(state){
        //     if(!state.permission){
        //         state.permission = JSON.parse(sessionStorage.getItem("permission"))
        //     }
        //     return state.permission
        // },
        tzxtsz(state){
            if(!state.tzxtsz){
                state.tzxtsz = JSON.parse(sessionStorage.getItem('tzxtsz'))
            }
        },
        token(state){
            if(!state.token){
                state.token = JSON.parse(sessionStorage.getItem('token'))
            }
            return state.token
        },
		system(state){
		    if(!state.system){
		        state.system = JSON.parse(sessionStorage.getItem('permission'))
		    }
		    return state.system
		},
		TabStatus(state){
		    if(!state.TabStatus){
		        state.TabStatus = JSON.parse(sessionStorage.getItem('TabStatus'))
		    }
		    return state.TabStatus
		},
        // userid(state){
        //     if(!state.userid){
        //         state.userid = JSON.parse(localStorage.getItem('userid'))
        //         console.log(JSON.parse(localStorage.getItem('userid')))
        //     }
        //     return state.userid
        // }
    },
    mutations:{//唯一允许改变state
		setTabStatus(state,v){
			state.TabStatus = v
			sessionStorage.setItem("TabStatus",JSON.stringify(v))
		},
		setsystem(state,v){
			state.system = v
			sessionStorage.setItem("permission",JSON.stringify(v))
		},
        setuserid(state,v){
            state.userid = v
            localStorage.setItem("userid",JSON.stringify(v))
        },
        settoken(state,v){
            state.token = v
            sessionStorage.setItem("token",JSON.stringify(v))
        },
        setCrumbs(state,v){
            state.crumbs = v 
        },

        setname(state,v){
            state.user = v 
            sessionStorage.setItem("key",JSON.stringify(v))
        },
        
        setpermission(state,v){
            state.permission = v 
            sessionStorage.setItem("permission",JSON.stringify(v))
        },
        removename(state,v){
            state.user = null
            sessionStorage.removeItem("key")
        },
        setStorge(state,v){
            state.newStorge = v
        },

        settzxtsz(state,v){
            state.tzxtsz = v
            sessionStorage.setItem("tzxtsz",JSON.stringify(v))
        },


        setnum(state,v){
            state.num = v
        },
        settype(state,v){
            state.type = v
        },
        // 设置类型
        setStorName(state,v){
            state.storName = v
            
        },
        removeRuform(state,v){
            state.newStorge= null
        },
        // 设置分页
        // setPagNum(state,v){
        //     state.pagNum = v
        // }
    },
    actions:{//触发更改

    },

})

export default store